package factory.one.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.concurrent.TimeUnit;

/**
 * @author 支绍昆
 * 2023/2/2
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        CacheControl oneHour = CacheControl.maxAge(1, TimeUnit.HOURS);
        //默认static下,可以不指定.
        registry.addResourceHandler("/images/**").addResourceLocations("classpath:/images/").setCacheControl(oneHour);
        registry.addResourceHandler("/css/**").addResourceLocations("classpath:/css/").setCacheControl(oneHour);
        registry.addResourceHandler("/js/**").addResourceLocations("classpath:/js/").setCacheControl(oneHour);
    }

}
